/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uk.ac.bath.domains.prey;

import uk.ac.bath.base.Cell;
import uk.ac.bath.base.EnvironmentIF;
import uk.ac.bath.base.MachineIF;
import uk.ac.bath.base.VectorState;

/**
 *
 * @author pjl
 */
public abstract class BasicCell extends Cell {

    float vel; // motion ints per tick
    MyDirection dir; // facing
    MyPoint tmp = new MyPoint();
    static int id = 0;
    protected boolean collided;

    protected BasicCell(MachineIF machine, MyPoint point, String tag, double fitness) {
        super(machine, point, fitness, id++, 0, 0, tag);
        vel = 0.0f;

        dir = new MyDirection();

    }

    public MyPoint nextPointMayBe() {
        MyPoint.project((MyPoint) point, dir, vel, tmp);
        return tmp;
    }

    public void moveTo(MyPoint p) {
        ((MyPoint) point).x = p.x;
        ((MyPoint) point).y = p.y;
        collided = false;
    }

    void collide() {
        collided = true;
    }

    MyPoint getMyPoint() {
        return (MyPoint) point;
    }

    final protected void tickImpl() {
        //     VectorState state = machine.getState();
        preMachineTick(machine);

        if (machine != null) {
            machine.tick();
        }

        //   state=machine.getState();
        postMachineTick(machine);
    }

    abstract protected void postMachineTick(MachineIF machine);

    abstract protected void preMachineTick(MachineIF machine);
}
